package Server.junit;

import common.exception.ExtinctionException;

import Server.players.Carnivorous;
import Server.players.Dino;
import Server.players.Player;
import junit.framework.TestCase;

public class PlayerTest extends TestCase {

	private Player p;
	protected void setUp() throws Exception {
		super.setUp();
		p = new Player("pippo", "pluto");
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testPlayerStringString() {
		Player p1 = new Player("pippo", "pluto");
		assertEquals(p, p1);
	}

	public void testPlayerPlayer() {
		Player p1 = new Player(p);
		assertEquals(p, p1);
	}

	public void testNewSpecies() {
		p.newSpecies("carn", 'c');
		assertTrue(p.getSpeciesName().equals("carn"));
		assertTrue(p.getSpeciesType() == 'c');
	}

	public void testGetDinoList() {
		p.newSpecies("carn", 'c');
		Integer[] d = p.getDinoList();
		assertTrue(d.length == 0);
		p.newDino(1);
		d = p.getDinoList();
		assertTrue(d.length == 1);
		assertTrue(d[0] == 1);
	}

	public void testAuthenticate() {
		assertTrue(p.authenticate("pluto"));
	}

	public void testOwns() {
		Carnivorous c = new Carnivorous(1);
		assertFalse(p.owns(c));
		p.newSpecies("carn", 'c');
		p.newDino(1);
		assertTrue(p.owns(c));
	}

	public void testGetDino() {
		Carnivorous c = new Carnivorous(1);
		p.newSpecies("carn", 'c');
		p.newDino(1);
		Dino d = p.getDino(1);
		assertEquals(c, d);
	}

	public void testRemoveDino() {
		Carnivorous c = new Carnivorous(1);
		p.newSpecies("carn", 'c');
		p.newDino(1);
		assertTrue(p.owns(c));
		p.removeDino(c);
		assertFalse(p.owns(c));
	}

	public void testOneTurnOlder() {
		p.newSpecies("carn", 'c');
		p.newDino(1);
		Dino d = p.getDino(1);
		int age = d.getAge();
		try{
			p.oneTurnOlder(true);
		} catch (ExtinctionException e){
			fail();
		}
		assertTrue(age + 1 == p.getDino(1).getAge());
	}

}
